﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;

namespace Te.Bigscreen.Service
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string template =
                "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}";

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Async(a => a.Console(outputTemplate: template))
                .WriteTo.Async(a =>
                    a.File(
                        "logs/svr-.log",
                        outputTemplate: template,
                        rollingInterval: RollingInterval.Day
                    )
                )
                .CreateLogger();

            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(cfg =>
                {
                    cfg.UseStartup<Startup>();
                    cfg.UseUrls("http://*:5000");
                })
                .UseSerilog();
    }
}
